package com.gitee.wsl.ext.map

fun <K,V> Map<K,V>.groupBy(keyCall:(K)->K={it}, valueSum:(V,V)->V):Map<K,V>{
    val ret = mutableMapOf<K,V>()
    forEach{
        val subKey=keyCall(it.key)
        val subSum:V? = ret[subKey]
        if(subSum!=null)
            ret[subKey] = valueSum(subSum,it.value)
        else
            ret[subKey] = it.value
    }
    return ret
}
